package com.iot08.common.utils;

/**
 * @version 1.0
 * @Description: 位置相关工具类
 * @time: 2021/5/27 10:00
 * @author: Rock
 */
public class PositionUtil {

    /**
     * 计算两个经纬度坐标间距
     *
     * @param lastlon
     * @param lastlat
     * @param nowlon
     * @param nowlat
     * @time: 2021/2/25 11:00
     * @author: Rock
     * @version 1.0
     */
    public static double getDistance(double lastlon, double lastlat, double nowlon, double nowlat) {
        if (lastlon == nowlon && lastlat == nowlat) {
            return 0;
        } else {
            double x = Math.PI / 180.0;
            lastlon = lastlon * x;
            lastlat = lastlat * x;
            nowlon = nowlon * x;
            nowlat = nowlat * x;
            double con = Math.sin(lastlat) * Math.sin(nowlat);
            con += Math.cos(lastlat) * Math.cos(nowlat) * Math.cos(lastlon - nowlon);
            if (con > 1) {
                con = (int) con;
            }
            return Math.acos(con) * 6371137.0d;
        }
    }


}
